#coding=utf-8
from bottle import static_file, route
from config import config
import runtime
import bottle

bottle.TEMPLATE_PATH = [config.TEMPLATE_PATH]
bottle.STATIC_PATH = config.STATIC_PATH

@route('/static/:path#.+#')
def server_static(path):
	return static_file(path, root=bottle.STATIC_PATH)

# from handler import test
# bottle.mount('/a', test.url.url)
from lib import echo
def include(p):
	import os
	path = os.getcwd()
	import_path = path
	for i in p:
		import_path = os.path.join(import_path, i)
	for p,d,f in os.walk(import_path):
		for name in f:
			if '__init__' not in name:
				if '.py' in name and '.pyc' not in name:
					import_name = p.split(path)[1]
					import_name = import_name.replace('\\', '.')
					import_name = import_name.replace('/', '.')
					imp = import_name[1:] + '.' + name[:-3]
					try:
						stmp = __import__(imp)
						echo.success('import:' + imp)
					except Exception, e:
						from lib import logs
						echo.error('import_error:' + imp)
						import traceback
						echo.error(traceback.format_exc())

include(['web', 'handler'])
include(['lib'])
print '[import finish]'